September 5th
1. the use of bisects in python
binary search:
when we want to search an element in a list, we can take the middle value, find out the target is bigger than the middle or not, then we can abandon half of a list. keep on doing it, we can find it at last. the maximum time we take is log2n.
2. the example
2.1 iteration binary search
use iteration to make a binary search function, it's faster than recursion in binary search. but iteration use counter as the condition of a loop, when all the number count off, the loop will finish.
1. the use of bisects in python
binary search:
when we want to search an element in a list, we can take the middle value, find out the target is bigger than the middle or not, then we can abandon half of a list. keep on doing it, we can find it at last. the maximum time we take is log2n.
2. the example
2.1 iteration binary search
use iteration to make a binary search function, it's faster than recursion in binary search. but iteration use counter as the condition of a loop, when all the number count off, the loop will finish.
2.2 recursive binary search
recursion use the output as input again, the code will shorter than iteration, but it's slower,use more RAM.